package edu.njust.underwater.controller;

import edu.njust.underwater.common.Result;
import edu.njust.underwater.pojo.Comment;
import edu.njust.underwater.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/comments/{id}")
    public Result getAll(@PathVariable Long id) {

        return commentService.getAll(id);

    }


    @PostMapping("/addComment/{articleId}")
    public Result add(@PathVariable Long articleId, Comment comment){
        return commentService.addOne(articleId, comment);
    }


    @PostMapping("/sortComments/{articleId}")
    public Result sort(@PathVariable Long articleId, String sortType) {

        return commentService.sortBy(articleId, sortType);

    }

    @PostMapping("/addLikes/{articleId}")
    public Result addLikes(@PathVariable Long articleId, Comment comment) {
        return commentService.addLike(comment);
    }

}
